﻿using System;
using System.ServiceModel;

namespace SyncComm.Service.Host
{
    class Program
    {

        static void Main(string[] args)
        {

            var hostDefault = new ServiceHost(typeof(SyncService));

            // Print servicehost info --> see ExtensionMethod class
            Console.WriteLine(hostDefault.ToFormattedString());

            // Hosting...
            using (var serviceHost = new ServiceHost(typeof(SyncService)))
            {
                try
                {
                    // Open the ServiceHost to start listening for messages.
                    serviceHost.Open();
                    
                    // The service can now be accessed.
                    Console.WriteLine("The service is ready.");
                    Console.WriteLine("Press <ENTER> to terminate service.");
                    Console.ReadLine();

                    // Close the ServiceHost.
                    serviceHost.Close();
                    Console.WriteLine("The service is closed.");
                    //Console.WriteLine("Press <ENTER> to exit.");
                    //Console.Read();
                }
                catch (TimeoutException timeoutException)
                {
                    Console.WriteLine(timeoutException.Message);
                    Console.ReadLine();
                }
                catch (CommunicationException communicationException)
                {
                    Console.WriteLine(communicationException.Message);
                    Console.ReadLine();
                }
                catch (Exception exception)
                {
                    Console.WriteLine(exception.Message);
                    Console.ReadLine();
                }
            }

        }
    }
}
